<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=Edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="renderer" content="webkit">

	<title>Login</title>
	<link href="css/login.css" rel="stylesheet">
	
	<script src="js/jquery-1.10.2.min.js"></script>
	<script src="js/bootstrap.min.js"></script>
	<script src="js/modernizr.min.js"></script>
	<script type="text/javascript" src="js/jquery.cookie.js"></script>
    <script type="text/javascript">
	$().ready(function() {
		if ($.cookie("rmbUser") == "true") {
			$("#ck_rmbUser").attr("checked", true);
			$("#user_id").val($.cookie("user_id"));
			$("#password").val($.cookie("password"));
			$("#fromEntity").val($.cookie("fromEntity"));
			if (null != $.cookie("project_code"))
				$("#project_code").val($.cookie("project_code"));

		}

		$("body").keypress(function(e) {
			if (e.which == 13) {
				check();
				return false;
			}
		});
	});

	function check() {
		var a = document.getElementById("user_id").value.length;
		var b = document.getElementById("password").value.length;
		if (a == 0) {
			document.getElementById("errorinfo").style.display = "block";
		} else if (b == 0) {
			document.getElementById("errorinfo2").style.display = "block";
		} else {
			var checked = document.getElementById("ck_rmbUser").checked;
			if (checked) {
				var str_username = $("#user_id").val();
				var str_password = $("#password").val();
				var str_fromEntity = $("#fromEntity").val();
				$.cookie("rmbUser", "true", {
					expires : 365
				});
				$.cookie("user_id", str_username, {
					expires : 365
				});
				$.cookie("password", str_password, {
					expires : 365
				});
				$.cookie("fromEntity", str_fromEntity, {
					expires : 365
				});
			} else {
				$.cookie("rmbUser", "false", {
					expire : -1
				});
				$.cookie("user_id", "", {
					expires : -1
				});
				$.cookie("password", "", {
					expires : -1
				});
				$.cookie("fromEntity", "", {
					expires : -1
				});

			}
			login();
		}
	}

	function login() {
		$.ajax({
			type : "POST",
			url : "/login",
			dataType : "json",
			data : {
				"username" : $("#user_id").val(),
				"password" : $("#password").val()
			},
			success : function(data) {
				if (data.code == "1") {
					/* window.location.href="/loginIndex"; */
					location.href='/';
				} else {
					$("#errorinfo3").html(data.msg);
					$("#errorinfo3").show();
				} 
			}
		});

	}

	

	function cleantip_user() {
		document.getElementById("errorinfo").style.display = "none";
		document.getElementById("errorinfo3").style.display = "none";
	}
	function cleantip_pwd() {
		document.getElementById("errorinfo2").style.display = "none";
		document.getElementById("errorinfo3").style.display = "none";
	}
</script>
</head>

<body class="login-body">
		<div class="login">
				<div class="left_part">
						<div class="logo">
							<div>
								<p>ERP查询系统</p>
								<p>Enterprice Resource Planning Query System</p>
							</div>
						</div>
				</div>
				<div class="right_part">
						<div class="login_form">
							<div class="border_line">
								<div>
								<p class="title"><span>欢迎登录</span></p>
								<div class="form" >
									<p>用户名：<input  type="text" class="form-control" name="user_id"  id="user_id" placeholder="请输入用户名" onfocus="cleantip_user()" autofocus ></p>
									<p>密&nbsp;&nbsp;&nbsp;码：<input type="password" class="form-control" id="password" name="password" placeholder="请输入登录密码" onfocus="cleantip_pwd()"></p>
									<p class="checkbox"><label><input type="checkbox" value="" id="ck_rmbUser"> 记住用户名</label></p>
								</div>
								<div align="center" style="color: red;">
									<i style="display: none" id="errorinfo3">用户名或密码错误</i> <i
										style="display: none" id="errorinfo2">*密码不能为空</i> <i
										style="display: none" id="errorinfo">*用户名不能为空</i>
								</div>
								<div class="submit_btn">
										<button class="btn btn-lg btn-login btn-block" type="button" onclick="check();">登录</button> 
								</div>
								<p class="links">
									<a href="http://sw.bos.baidu.com/sw-search-sp/software/89c331de74e21/ChromeStandalone_61.0.3163.100_Setup.exe">建议使用最新版chrome浏览器，下载最新版chrome</a>
								</p>
							</div>
							</div>
						</div>
				</div>
			</div>
		


</body>
</html>
